package com.benew.ntt.player.effect;

import android.media.audiofx.AudioEffect;

import com.ntt.core.nlogger.NLogger;

import java.util.UUID;

public class AwsFXWrapper {

    private static final String TAG = "AwsmFXWrapper";

    private static final UUID EFFECT_TYPE_AWSM = UUID.fromString("cae6f6c8-6ee0-47ab-9d24-b8c175dab49a");
    private static final UUID EFFECT_TYPE_CUSTOM = UUID.fromString("f98765f4-c321-5de6-9a45-123459495ab2");

    private AudioEffect audioEffect;


    public AwsFXWrapper(int sessionId) {
        try {
            audioEffect = AudioEffect.class.getConstructor(UUID.class, UUID.class,
                    Integer.TYPE, Integer.TYPE).newInstance(
                    EFFECT_TYPE_CUSTOM, EFFECT_TYPE_AWSM, 0, sessionId);
            AudioEffect.Descriptor descriptor = audioEffect.getDescriptor();
            NLogger.i(TAG, "Effect name: " + descriptor.type + "\nUnique ID: " + descriptor.uuid +
                    "\nImplementor: " + descriptor.implementor + " Id: " + audioEffect.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public void setEnabled(boolean enable) {
        if (audioEffect == null) {
            return;
        }
        audioEffect.setEnabled(enable);
    }

    public boolean isEnabled() {
        return audioEffect != null && audioEffect.getEnabled();
    }

    public int getId() {
        if (audioEffect == null) {
            return 0;
        }
        return audioEffect.getId();
    }


    public void release() {
        if (audioEffect != null) {
            audioEffect.release();
            audioEffect = null;
        }
    }
}
